package org.dromara.vehicle.modules.driver.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.vehicle.modules.driver.domain.bo.DriverBasicInfoBo;
import org.dromara.vehicle.modules.driver.domain.vo.DriverBasicInfoVo;
import org.dromara.vehicle.modules.driver.service.IDriverBasicInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 驾驶员基本信息
 *
 * @author ckk
 * @date 2025-06-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/vehicle/driverBasicInfo")
public class DriverBasicInfoController extends BaseController {

    private final IDriverBasicInfoService driverBasicInfoService;

    /**
     * 查询驾驶员基本信息列表
     */
    @SaCheckPermission("vehicle:driverBasicInfo:list")
    @GetMapping("/list")
    public TableDataInfo<DriverBasicInfoVo> list(DriverBasicInfoBo bo, PageQuery pageQuery) {
        return driverBasicInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出驾驶员基本信息列表
     */
    @SaCheckPermission("vehicle:driverBasicInfo:export")
    @Log(title = "驾驶员基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DriverBasicInfoBo bo, HttpServletResponse response) {
        List<DriverBasicInfoVo> list = driverBasicInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "驾驶员基本信息", DriverBasicInfoVo.class, response);
    }

    /**
     * 获取驾驶员基本信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("vehicle:driverBasicInfo:query")
    @GetMapping("/{id}")
    public R<DriverBasicInfoVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(driverBasicInfoService.queryById(id));
    }

    /**
     * 新增驾驶员基本信息
     */
    @SaCheckPermission("vehicle:driverBasicInfo:add")
    @Log(title = "驾驶员基本信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DriverBasicInfoBo bo) {
        return toAjax(driverBasicInfoService.insertByBo(bo));
    }

    /**
     * 修改驾驶员基本信息
     */
    @SaCheckPermission("vehicle:driverBasicInfo:edit")
    @Log(title = "驾驶员基本信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DriverBasicInfoBo bo) {
        return toAjax(driverBasicInfoService.updateByBo(bo));
    }

    /**
     * 删除驾驶员基本信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("vehicle:driverBasicInfo:remove")
    @Log(title = "驾驶员基本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(driverBasicInfoService.deleteWithValidByIds(List.of(ids), true));
    }
}
